//
//  MusicRootViewController.m
//  PlayerFix
//
//  Created by DAT on 15/11/5.
//  Copyright © 2015年 DAT. All rights reserved.
//

#import "MusicRootViewController.h"
#import "RecommendViewController.h"
#import "HotListViewController.h"

@interface MusicRootViewController ()<UIScrollViewDelegate>


@property (nonatomic, strong) UIScrollView *backgroundScrollView;
@property (nonatomic, strong) UIScrollView *titleScrollerView;

@property (nonatomic, strong) RecommendViewController *recommendVC;
@property (nonatomic, strong) HotListViewController *hotListVC;

@property (nonatomic, strong) UILabel *recommendLabel;
@property (nonatomic, strong) UILabel *hotlistLabel;
@property (nonatomic, strong) UIButton *recommendBtn;
@property (nonatomic, strong) UIButton *hotlistBtn;



@end

@implementation MusicRootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
//    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"Menu" style:UIBarButtonItemStyleDone target:self action:@selector(presentLeftMenuViewController)];
    
//    self.segmentControl = [[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects:@"音乐",@"影视", nil]];
//    self.navigationItem.titleView = _segmentControl;
//    _segmentControl.frame = CGRectMake(0, 0, 180, 30);
//    _segmentControl.tintColor = [UIColor lightGrayColor];
//    _segmentControl.selectedSegmentIndex = 0;
    
    if (self.navigationController) {
        
        NSLog(@"aaaaaaaaaaaaaaaa");
    }
    
    self.backgroundScrollView = [[UIScrollView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.backgroundScrollView.contentSize = CGSizeMake(self.view.frame.size.width * 2, 0);
    self.backgroundScrollView.showsHorizontalScrollIndicator = NO;
    self.backgroundScrollView.showsVerticalScrollIndicator = NO;
    self.backgroundScrollView.bounces = NO;
    _backgroundScrollView.scrollsToTop = NO;
    [self.backgroundScrollView showsHorizontalScrollIndicator];
    [self.backgroundScrollView setPagingEnabled:YES];
    self.backgroundScrollView.delegate = self;
    self.backgroundScrollView.hidden = NO;
    [self.view addSubview:self.backgroundScrollView];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
//    self.titleScrollerView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 375, 30)];
//    self.titleScrollerView.showsHorizontalScrollIndicator = NO;
//    self.titleScrollerView.showsVerticalScrollIndicator = NO;
//    self.titleScrollerView.backgroundColor = [UIColor whiteColor];
//    self.titleScrollerView.bounces = YES;
//    [self.titleScrollerView setPagingEnabled:YES];
//    self.titleScrollerView.delegate = self;
//    self.titleScrollerView.hidden = NO;
//    [self.view addSubview:self.titleScrollerView];

    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 375, 30)];
    titleLabel.backgroundColor = RGBA(30, 80, 100, 1);
    [self.view addSubview:titleLabel];
    
    self.recommendBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.recommendBtn.frame = CGRectMake(100, 0, 50, 30);
    [self.recommendBtn setTitle:@"推荐" forState:UIControlStateNormal];
    [self.recommendBtn setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
    [self.view addSubview:self.recommendBtn];
    [self.recommendBtn addTarget:self action:@selector(recommendBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.recommendLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 28, 50, 3)];
    self.recommendLabel.backgroundColor = [UIColor greenColor];
    [self.view addSubview:self.recommendLabel];
    
    self.hotlistBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.hotlistBtn.frame = CGRectMake(220, 0, 50, 30);
    [self.hotlistBtn setTitle:@"热门" forState:UIControlStateNormal];
    [self.hotlistBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.hotlistBtn addTarget:self action:@selector(hotlistBtnAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.hotlistBtn];
    
    self.recommendVC = [[RecommendViewController alloc] init];
    self.recommendVC.view.frame = CGRectMake(0, 30, 375, 667 - 30 - 64);
    [self.backgroundScrollView addSubview:self.recommendVC.view];
    
    self.hotListVC = [[HotListViewController alloc] init];
    self.hotListVC.view.frame = CGRectMake(375, 30, 375, 667 - 30 - 64);
    [self.backgroundScrollView addSubview:self.hotListVC.view];
    
    

}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    CGFloat x = scrollView.contentOffset.x / 375.0 * 120;
    self.recommendLabel.frame = CGRectMake(100 + x, 28, 50, 2);
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    if (self.backgroundScrollView.contentOffset.x / 375 == 0) {
        
        [self.recommendBtn setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        [self.hotlistBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        self.recommendLabel.frame = CGRectMake(100, 28, 50, 2);
    }
    else if (self.backgroundScrollView.contentOffset.x / 375 == 1){
        
        [self.recommendBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self.hotlistBtn setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
        self.recommendLabel.frame = CGRectMake(220, 28, 50, 2);
    }
}

- (void)hotlistBtnAction:(UIButton *)btn{
    
    [self.backgroundScrollView setContentOffset:CGPointMake(375, 0) animated:YES];
    [self.recommendBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.hotlistBtn setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
}

- (void)recommendBtnAction:(UIButton *)btn{
    
    [self.backgroundScrollView setContentOffset:CGPointMake(0, 0) animated:YES];
    [self.recommendBtn setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
    [self.hotlistBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    }

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
